package com.dmwork.service.interaction.controller.front;


import com.dmwork.common.base.result.R;
import com.dmwork.service.interaction.service.CmsColorService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisKeyValueTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 网页颜色数据表 前端控制器
 * </p>
 *
 * @author 李天
 * @since 2021-10-24
 */
@RestController
@RequestMapping("/front/dm_work/interaction/cms_color/")
public class FrontCmsColorController {

    @Autowired
    private CmsColorService cmsColorService;

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("根据颜色命名获取颜色信息")
    @GetMapping("get_color_by_color_key/{colorKey}")
    public R getColorByColorKey(@PathVariable String colorKey) {
        String colorValue = (String) redisTemplate.opsForValue().get(colorKey);
        if (StringUtils.isEmpty(colorValue)) {
            colorValue=cmsColorService.getColorValueByColorKey(colorKey);
            redisTemplate.opsForValue().set(colorKey, colorValue);
        }
        return R.ok().data("colorValue", colorValue);
    }

}

